<?php
/**
 * Created by PhpStorm.
 * User: Acer
 * Date: 2022/7/30
 * Time: 23:00
 */

namespace app\admin\service;


use app\admin\models\BannerModel;

class BannerService{

    // 获取banner列表
    public function s_get_list($is_active = false){
        $BannerModel = new BannerModel();
        if($is_active){
            $BannerModel->where('state',1);
        }
        return $BannerModel->order('sort')->select();
    }


    // 新增banner
    public function s_add_banner($data){
        $BannerModel = new BannerModel();
        $installData = [
            'img'   =>  $data['img'],
        ];
        if(isset($data['link'])) $installData['link'] = $data['link'];
        if(isset($data['sort'])) $installData['sort'] = $data['sort'];
        return $BannerModel->insert($installData);
    }

    // 修改banner
    public function s_modify_banner($data){
        $BannerModel = new BannerModel();
        $updataData = [
            'img'   =>  $data['img'],
        ];
        if(isset($data['link'])) $updataData['link'] = $data['link'];
        if(isset($data['state'])) $updataData['state'] = $data['state'];
        if(isset($data['sort'])) $updataData['sort'] = $data['sort'];
        $BannerModel->where('bid',$data['bid'])->update($updataData);
    }

    // 删除banner
    public function s_del_banner($bid){
        $BannerModel = new BannerModel();
        return $BannerModel->where('bid',$bid)->delete();
    }
}
